package com.yifeng.repo.controller.statemachine.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by daibing on 2024/9/20.
 */
@Getter
@AllArgsConstructor
public enum StatemachineEnum {
    ACCOUNT_MACHINE("acct","账号状态机"),
    AUDIT_MACHINE("audit","审核状态机"),
    TASK_MACHINE("task","任务状态机"),
    PRESCRIPTION_MACHINE("Rx","处方状态机"),
    ORDER_MACHINE("order","订单状态机"),
    PAYMENT_MACHINE("pay","付款状态机"),
    DELIVERY_MACHINE("del","配送状态机");

    @EnumValue
    @JsonValue
    private final String code;

    private final String name;

    private static final Map<String, StatemachineEnum> mappings = new HashMap<>(8);

    static {
        for (StatemachineEnum value : values()) {
            mappings.put(value.getCode(), value);
        }
    }

    public static StatemachineEnum resolve(String code) {
        return (code != null ? mappings.get(code) : null);
    }
}
